[Enh] Add finer FastMathFlag control#789
Open
sjfeng1999 wants to merge 8 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces an “ambient” fast-math mechanism so floating-point ops can automatically inherit fastmath flags from (1) a with fx.fastmath(...) context and (2) a compile hint (kernel/JIT scope), while still allowing per-op explicit overrides.
Changes:
- Add a thread-local ambient fastmath context manager and propagate it through overloaded float ops and selected helpers.
- Teach math-dialect wrappers to inherit ambient fastmath when
fastmathisn’t explicitly provided. - Apply compile-hint
fastmathas a scope around kernel/JIT body emission and add tests for scoping/overrides/cache keys.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/test_fastmath_context.py | New tests for ambient fastmath propagation, overrides, and hint/cache-key behavior. |
| python/flydsl/expr/utils/arith.py | Adds thread-local ambient fastmath context + propagates flags through float operators and selected helpers. |
| python/flydsl/expr/typing.py | Attempts to propagate fastmath into Vector.reduce, but currently introduces a NameError. |
| python/flydsl/expr/math.py | Enhances wrapper decorator to inject ambient fastmath and support non-first “exemplar” operands. |
| python/flydsl/expr/arith.py | Extends arith wrapper surface and uses the math wrapper decorator for result typing. |
| python/flydsl/compiler/kernel_function.py | Applies compile-hint fastmath via a context manager around kernel-body emission. |
| python/flydsl/compiler/jit_function.py | Applies compile-hint fastmath via a context manager around JIT-body emission. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Technical Details
Test Plan
Test Result
Submission Checklist